package com.multidisplay.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.multidisplay.bo.InfoBo;
import com.multidisplay.bo.ResultBo;
import com.multidisplay.mapper.WebPageMapper;
import com.multidisplay.po.WebPage;
import com.multidisplay.service.WebPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WebPageServiceImpl implements WebPageService {
    @Autowired
    private WebPageMapper webPageMapper;

    @Override
    public void alterImage(WebPage webPage){  //前端传回的webPage的imageURL已经更改了？
        webPageMapper.updateById(webPage);
    }   //根据图片ID修改页面背景图片

    @Override
    public void alterNavBars(WebPage webPage){
        webPageMapper.updateById(webPage);
    }    //根据导航ID修改页面导航条样式

    @Override
    public InfoBo<String> queryOfFlag(String flag){
        QueryWrapper<WebPage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("flag",flag);
        WebPage webPage = webPageMapper.selectOne(queryWrapper);
        InfoBo<String> infoBo = new InfoBo<>();
        infoBo.setCode(0);
        infoBo.setMsg("根据页面标识符"+flag+"查得的页面信息");
        infoBo.setData(webPage.toStringList());
        return infoBo;
    } //根据页面标识符查询对应的页面信息

    @Override
    public ResultBo<WebPage> queryAll(int page, int limit){
        IPage iPage = new Page(page,limit);
        IPage<WebPage> userIPage = webPageMapper.selectPage(iPage,null);
        ResultBo<WebPage> resultBo = new ResultBo<>();
        resultBo.setCode(0);
        resultBo.setMsg("");
        resultBo.setCount(userIPage.getTotal());
        resultBo.setData(userIPage.getRecords());
        return resultBo;
    }   //分页查询页面信息

    @Override
    public ResultBo<WebPage> queryOfResolution(int page, int limit, String resolution){
        IPage iPage = new Page(page,limit);
        QueryWrapper<WebPage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("resolution", resolution);
        IPage<WebPage> pagesIPage = webPageMapper.selectPage(iPage,queryWrapper);
        ResultBo<WebPage> resultBo = new ResultBo<>();
        resultBo.setCode(0);
        resultBo.setMsg("");
        resultBo.setCount(pagesIPage.getTotal());
        resultBo.setData(pagesIPage.getRecords());
        return resultBo;
    }    //根据分辨率查询页面信息

    @Override
    public ResultBo<WebPage> queryOfPid(int page, int limit, String pid){
        IPage iPage = new Page(page, limit);
        QueryWrapper<WebPage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", pid);
        IPage<WebPage> pagesIPage = webPageMapper.selectPage(iPage,queryWrapper);
        ResultBo<WebPage> resultBo = new ResultBo<>();
        resultBo.setCode(0);
        resultBo.setMsg("");
        resultBo.setCount(pagesIPage.getTotal());
        resultBo.setData(pagesIPage.getRecords());
        return resultBo;
    } //根据页面父ID查询对应的页面信息
}
